package com.athena.objects;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


import com.smartfoxserver.v2.entities.User;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import sfs2x.extension.fourinarow.main.FourinarowExtension;

/**
 *
 * @author dodinhchien
 */
public class Player {
    private User sfsUser; 
    private int mark;
    private int id;
    private int playerId;
    private String username;
    private int roomId = -1;
    private boolean disconnect = false;

    public boolean isDisconnect() {
        return disconnect;
    }

    public void setDisconnect(boolean disconnect) {
        this.disconnect = disconnect;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getPlayerId() {
        return playerId;
    }

    public void setPlayerId(int playerId) {
        this.playerId = playerId;
    }
    
    public Player(User sfsUser, int mark) {
        this.id = sfsUser.getId();
        this.sfsUser = sfsUser;
        this.mark = mark;
        this.username = sfsUser.getName();
    }

    

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    
    public int getRoomId() {
        return roomId;
    }

    public void setRoomId(int roomId) {
        this.roomId = roomId;
    }

    public User getSfsUser() {
        return sfsUser;
    }

    public void setSfsUser(User sfsUser) {
        this.sfsUser = sfsUser;
    }

    public int getMark() {
        return mark;
    }

    public void setMark(int mark) {
        this.mark = mark;
    }
    public void updateMark(FourinarowExtension extension, int m) throws SQLException{
        this.mark += m;
        Connection conn ;
        conn = extension.getParentZone().getDBManager().getConnection();
        PreparedStatement sql = conn.prepareStatement("{call UpdateMark(?,?)}");
        sql.setString(1, sfsUser.getName());
        sql.setInt(2, this.mark);
        sql.execute();
        conn.close();
    }
}
